<?php
function error_td($error) {
  echo  '<tr>
          <td class="error" colspan="2">'
          . $error .
          '</td>
        </tr>';
}
?>
<style type="text/css">

td.error {
  color: red;
  font-size:13px;
  text-align:center;
}
body {
   font-family:verdana,arial;
}
table.canvas_table
{
  empty-cells: show;
  border-collapse: collapse;
  border: thin inset rgb(100,100,100);  
  background-color: rgb(255,255,255);
  align:center;
  vertical-align: middle;
  width:100%;
}
input.button
{
  border: thin outset rgb(100,100,100);
  background-color: rgb(220,220,220)
}
h2
{
  text-align:center;
  font-family:verdama;
  font-size:16px;
  overflow:hidden;
}
th
{
  font-family:verdama;
  font-size:14px;overflow:hidden;
}
a:hover {
  text-decoration:underline;
}
a {
  color:#3B5998;
  text-decoration:none;
}
div.table_title {
  text-align:center;
  font-family:verdama;
  font-size:20px;
  overflow:hidden;
  height:25px;
	vertical-align: bottom;
}
div.template_body {
  vertical-align: top;
  width:100%;
}
</style>
<div class="template_body">
  <div class="table_title">
  <?=$lang['appedit']['aplication_version_title'];?>
  </div>
<form action="<?=WS_HOME_DIR;?>editapp_iframe.php?<?=$_SERVER['QUERY_STRING'];?>" method="post" enctype="multipart/form-data">
<?php
if(isset($app)) {
?>
  <table class="canvas_table" id="app">
  		 <tr>
		     <td rowspan="3" width="62px">
		       <img src="<?=$app->getThumb();?>" border="0" style="height:60px;width:60px"/>
	       </td>
       </tr>
	     <tr>
	       <td style="width: 100px;">
	         <?=$lang['appedit']['title'];?>
	       </td>
	       <td>
	         <b><?=$app->getTitle();?></b>
	       </td>
	     </tr>
	     <tr>
	       <td>
	         <?=$lang['appedit']['description'];?>
	       </td>
	       <td>
	         <div class="app_description"><?=$app->getDescription();?></div>
	       </td>
	     </tr>
  </table>
<?php
} else {
?>
  <table class="canvas_table" id="app">
     <tr>
       <td>
         <?=$lang['appedit']['title'];?>
       </td>
       <td>
         <input style="width:95%" type="text" name="title" value="<?=@$fill['title'];?>"/>
       </td>
     </tr>
<?php
  if(isset($errors['title'])) {
    error_td($errors['title']);    
  }
?>
     <tr>
       <td>
         <?=$lang['appedit']['description'];?>
       </td>
       <td>
         <div class="app_description">
	         <textarea style="height:50px; width: 95%" name="description"><?=@$fill['description'];?></textarea>
         </div>
       </td>
     </tr>
<?php
  if(isset($errors['description'])) {
    error_td($errors['description']);    
  }
?>
  </table>

<?php
}
?>
  <div class="table_title">
  <?=$lang['appedit']['upload_new_version_title'];?>
  </div>
 	<table class="canvas_table" id="upload_new_version">
     <tr>
       <td>
       <?=$lang['appedit']['version'];?>
       </td>
       <td>
         <input style="width:150px" type="text" name="version" value="<?=@$fill['version'];?>"/>
       </td>
     </tr>
<?php
  if(isset($errors['version'])) {
    error_td($errors['version']);    
  }
?>
     <tr>
       <td>
       <?=$lang['appedit']['upload'];?>
       </td>
       <td>
         <input style="width:95%" type="file" name="upload"/>
       </td>
     </tr>
     <tr>
       <td>
       <?=$lang['appedit']['or_url'];?>
       </td>
       <td>
         <input style="width:95%" type="text" name="url" value="<?=@$fill['url'];?>"/>
       </td>
     </tr>
<?php
  if(isset($errors['upload'])) {
    error_td($errors['upload']);    
  }
?>
<!--      <tr>
       <td>
       <?=$lang['appedit']['public'];?>
       </td>
       <td>
         <input type="checkbox" name="public"<?=(@$fill['public']?' checked':'');?>/>
       </td>
     </tr>
     <tr>
       <td>
       <?=$lang['appedit']['opensource'];?>
       </td>
       <td>
         <input type="checkbox" name="opensource"<?=(@$fill['opensource']?' checked':'');?>/>
       </td>
     </tr> -->
     <input type='hidden' name="public" value='1' />
     <input type='hidden' name="opensource" value='1' />
     <tr>
       <td colspan="2" style="text-align:center;">
         <input type="submit" name="submit" value="<?=$lang['appedit']['submit_new_version'];?>">
       </td>
     </tr>
  </table>
</form>
  
<?php
if(isset($app)) {
  $appVersions = array_reverse($app->getVersions());
  if(!empty($appVersions)){
  ?>
  <div class="table_title">
  <?=$lang['appedit']['version_list_title'];?>
  </div>
  <?php
    foreach($appVersions as $v) {
  //    $v = new AppVersion();
  ?>
      <table class="canvas_table" id="app_version_<?=$v->getId();?>">
        <tr>
          <td>
          <?=$lang['appedit']['version'];?>
          </td>
          <td>
            <?=$v->getVersion();?> - (<?=$v->getDate();?>)
          </td>
        </tr>
        <tr>
          <td>
          <?=$lang['appedit']['url'];?>
          </td>
          <td>
          	<input style="width: 90%" onclick="this.select();" onblur="this.value='<?=htmlentities($v->getUrl());?>'" type="text" value="<?=htmlentities($v->getUrl());?>"/>
          </td>
        </tr>
<!--         <tr>
          <td colspan="2">
          <?=$v->isPublic()?$lang['appedit']['ispublic']:$lang['appedit']['isnotpublic'];?> | 
          <?=$v->isOpensource()?$lang['appedit']['isopensource']:$lang['appedit']['isnotopensource'];?>
          </td>
        </tr> -->      
      </table><br />
<?php
    } 
  }
}
?>
</div>